package com.qf.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * 房东的代理对象
 * 前置
 * 后置
 * 异常
 * 环绕
 *
 * @author lixu
 * @Component == @Servcie == @Repository == @Controller  创建对象的作用：实例化的作用
 * <p>
 * JSP --->  Servlet  --> Service  --> Dao -->Druid -->Mysql
 * @Controller @Servcie
 * JSP --> SpringMvc --> Service --> Mapper -->Druid --> Mysql
 * ------------------------------------
 * @Component @Component
 * User POJO    AopA切面FangDongProxy代理对象
 * <p>
 * 语义：
 */
@Aspect //切面实现类注解
@Component //实例化注解
public class FangDongProxy {

    //抽取切入点
    @Pointcut(value = "execution(public * *.zufang(..))")
    public void pointcut() {
    }

    ;
    //前置通知
    /**
     * @Before(切入点)
     */
    //@Before(value = "pointcut()")
    public void beforeAdvice() {
        System.out.println("1:发布房子信息");
        System.out.println("2:带租客看房");
    }
    //后置通知

    /**
     * @AfterReturning(切入点)
     */
    //@AfterReturning(value = "pointcut()",returning = "result")
    public void afterReturningAdvice(Object result) {
        System.out.println("房东说：" + result);
        System.out.println("5:维修");
        System.out.println("6:转租");
    }

    //异常通知
    /**
     * @AfterThrowing(切入点)
     */
    //@AfterThrowing(value = "pointcut()",throwing = "e")
    public void afterThrowingAdvice(Exception e) {
        System.out.println("5:执行核心代码的时候，出现了异常:" + e.getMessage());
    }
    //环绕通知

    /**
     * @Around(切入点) JoinPoint jp:连接点
     *                ProceedingJoinPoint：子接口连接点（功能强大）
     */
    @Around(value = "pointcut()")
    public void aroundAdvice(ProceedingJoinPoint pjp) {
        System.out.println("1:发布房子信息");
        System.out.println("2:带租客看房");
        try {
            //回核心
            Object result = pjp.proceed();
            System.out.println("房东说：" + result);
            System.out.println("5:维修");
            System.out.println("6:转租");
        } catch (Throwable e) {
            //
            System.out.println("5:执行核心代码的时候，出现了异常:" + e.getMessage());
        }
    }


}
